<template>
    <div style="padding-top: 10px;height: 100%;">
        <a-spin :spinning="spinning">
            <div v-if="notYetStarted" class="budgetDeclaration-firstRound-none-div">
                <a-empty description="该环节暂未开始" />
                <h2  v-if="isCw && reportType == '财务审核(一上)'" @click="firstRoundStart" class="stepNum-four-title">点击开始一上</h2>
            </div>
            <div v-if="!notYetStarted">
                <toExamineModule ref="toExamineModuleRef" />
            </div>
        </a-spin>
    </div>
</template>
<script>
import {
    yssbSfcw,
    yssbGethjjdBynd,
    yssbInitBzFlow,
    yssbGetjhid,
} from './service/index'
import toExamineModule from './toExamine'
export default {
    components: {
        toExamineModule
    },
    props:{
        reportType:{
            type: String,
            default: '',
            required: false,
        }
    },
    data() {
        return {
            currentYear: null,
            isCw: false,
            notYetStarted: true,
            spinning: false
        }
    },
    mounted() {
        this.getYssbGethjjdBynd()
        // this.getData()
    },
    methods: {
        getYssbGethjjdBynd(){
            this.currentYear = new Date().getFullYear();
            this.spinning = true
            yssbGethjjdBynd().then(res => {
                if(res.success){
                    if(res.message == '流程未办'){
                        this.getYssbSfcw()
                        this.timeout = setTimeout(() => {
                            this.spinning = false
                        }, 1000);
                    } else if(res.message == '流程结束'){
                        this.notYetStarted = false
                        this.timeout = setTimeout(() => {
                            this.getData()
                        }, 1000);
                    } else {
                        this.handleFuntion(res.message)
                    }
                }
            })
        },
        // 是否财务
        getYssbSfcw(){
            yssbSfcw().then(res => {
                if(res.success && res.result){
                    this.isCw = res.result
                }
            })
        },
        async handleFuntion(linkName){
            let item = ['财务审核(一上)','办公室领导审核(一上)','领导班子审核(一上)','财务审核(二上)','办公室领导审核(二上)','领导班子审核(二上)']
            let pageIndexOf = item.indexOf(this.reportType)
            let indexOf = item.indexOf(linkName)
            let res = await yssbSfcw()
            this.isCw = res.result
            //console.log(indexOf,pageIndexOf,this.reportType,linkName)
            if(this.isCw){
                if(indexOf >= pageIndexOf){
                    this.notYetStarted = false
                    this.timeout = setTimeout(() => {
                        // //console.log('aaaaaaaaaaaaaaaaaaa',this.$refs.toExamineModuleRef)
                        if(this.$refs.toExamineModuleRef){
                            this.getData()
                        }
                    }, 1000);
                } else {
                    this.spinning = false
                }
            } else {
                if(indexOf > pageIndexOf){
                    this.notYetStarted = false
                }
                this.spinning = false
            }
        },
        async firstRoundStart(){
            let resA = await yssbGetjhid()
            var that = this
            that.$confirm({
                title:'点击开始后不再接收科室的后续填写数据，请确认所有科室已填写完毕，确认要开始一上吗？',
                onOk() {
                    let data = {
                        id: resA.result.jhid,
                        fsffqlc: '否',
                    }
                    yssbInitBzFlow(data).then(res => {
                        that.spinning = true
                        if(res.success){
                            that.notYetStarted = false
                            that.timeout = setTimeout(() => {
                                that.getData()
                            }, 1000);
                        } else {
                            that.$message.warning(res.message)
                        }
                        that.timeout = setTimeout(() => {
                            that.spinning = false
                        }, 1000);
                    })
                }
            })
        },
        getData(){
            // //console.log('HHHHHHHHHHHHHHH',this.$refs.toExamineModuleRef)
            this.$refs.toExamineModuleRef.getWriteData({flx: this.reportType},{heightType:'model'})
            this.spinning = false
        }
    }
}
</script>
<style lang="less">
.budgetDeclaration-firstRound-none-div {
    height: 100%;
    margin: 0 auto;
    .ant-empty {
        padding-top: 20%;
    }
    .stepNum-four-title {
        width: 200px;
        margin: 0.5em auto;
        text-align: center;
        font-family: '宋体' !important;
        font-weight: bold;
        margin-top: 0.5em;
        color: #5ca3e5;
        // border: 1px solid #e4e3e3;
        background-color: #e6f7ff;
        border-radius: 50px;
        padding: 5px;
    }
}
</style>
